import axios from 'axios';
import qs from 'qs' ;
import utils from './utils' ;


export const login = params => { 
	return utils.post('http://127.0.0.1:9000/api/login.json', qs.stringify(params)).then((res) => {
		return res.data 
	});
};



export const queryUsers = params => {return utils.get( 'http://127.0.0.1:9000/api/userManager/allUsers.json', params )
										.then( (res)=> {
											console.info( JSON.stringify(res))
											if ( res.code == -2 )
											{
												console.info(res) ;
												alert(2) ;
												$(this).$router.push({ path: '/login' });
											}
											return res.data
										}); 
									};
export const addNewUsers = params => { return utils.post('http://127.0.0.1:9000/api/userManager/add.json', qs.stringify(params)).then((res) => {return res.data}); };
export const delUsers = params => { return utils.get('http://127.0.0.1:9000/api/userManager/del/'+params.id+'.json').then((res) => {return res.data}); };
export const changeUsers = params => { return utils.post('http://127.0.0.1:9000/api/userManager/change.json',qs.stringify(params)).then((res) => {return res.data}); };
export const batchDelUsers = params => { return utils.post('http://127.0.0.1:9000/api/userManager/batchDel.json',qs.stringify(params)).then((res) => {return res.data}); };


export const searchRegisterUsers = params => {return utils.get( 'http://127.0.0.1:9000/api/registerUserManager/search.json', params )
										.then( (res)=> {
											console.info( JSON.stringify(res))
											if ( res.code == -2 )
											{
												console.info(res) ;
												alert(2) ;
												$(this).$router.push({ path: '/login' });
											}
											return res.data
										}); 
									};
export const addRegisterUsers = params => { return utils.post('http://127.0.0.1:9000/api/registerUserManager/register.json', qs.stringify(params)).then((res) => {return res.data}); };





let base = '';
export const requestLogin = params => { return axios.post('/login', params).then(res => res.data); };
export const getUserList = params => { return axios.get(`${base}/user/list`, { params: params }); };
export const getUserListPage = params => { return axios.get(`${base}/user/listpage`, { params: params }); };
export const removeUser = params => { return axios.get(`${base}/user/remove`, { params: params }); };
export const batchRemoveUser = params => { return axios.get(`${base}/user/batchremove`, { params: params }); };
export const editUser = params => { return axios.get(`${base}/user/edit`, { params: params }); };
export const addUser = params => { return axios.get(`${base}/user/add`, { params: params }); };